package xcmg.device.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import xcmg.device.infra.BasicController;
import xcmg.device.infra.ErrorCode;
import xcmg.device.infra.annotation.ExternalApiRequest;
import xcmg.device.service.basic.MaterialsService;
import xcmg.device.service.basic.SystemParameterService;
import yb.ecp.fast.infra.infra.ActionResult;

/**
 * @author wangyong
 */
@RestController
@RequestMapping("/parameter")
public class SystemParameterController extends BasicController {

  @Autowired
  private SystemParameterService systemParameterService;
  @Autowired
  private MaterialsService materialsService;

  @RequestMapping(value = "refreshParamCache",method = RequestMethod.GET)
  @ExternalApiRequest
  public ActionResult refreshParamCache(String paramKey) {
    try {
      systemParameterService.refreshParamCache(paramKey);
    } catch (Exception e) {
      return actionResult(ErrorCode.Failure, e.getMessage());
    }
    return actionResult(ErrorCode.Success);
  }

  @RequestMapping(value = "/test",method = RequestMethod.GET)
  public ActionResult test(String paramKey) {

    return actionValueResult(systemParameterService.listByParamType(paramKey));
  }


}
